<?php
class IndexAction extends Action{
	/**
	 * To login
	 * Enter description here ...
	 */
	public function index(){
		if(Session::get('islogin') == TRUE){
			$this->redirect('../Admin/space', '',0,'');
		}else{
		$this->display();
		}
	}
	/**
	 * Login ing>>>>>
	 */
	public function login(){
		$User = M('User');
		$data['username'] = $_POST['username'];
		$data['password'] = md5($_POST['password']);
		$data['lastloginip']= get_client_ip();
		$data['state']=1;
		$isReg=$User->where('username="'.$data['username'].'"')->find();
		if(!$isReg){
			$this->redirect('index', '',3,'This user is not registered!');
		}elseif ($isReg['password'] == $data['password']){
			Session::set('islogin', TRUE);
			Session::set('username', $data['username']);
			$User->where('username="'.$data['username'].'"')->save($data);
			$this->redirect('../Admin/space', '',3,'Succeed Login!');
		}else {
			$this->redirect('index', '',3,'The password is not valid!');
		}
	}
	/**
	 * to logout
	 * Enter description here ...
	 */
	public function logout(){
		Session::clear();
		Session::destroy();
		$this->assign('jumpUrl','index');
		$this->assign('waitSecond',2);
		$this-> success('登出成功');
	}
}
?>